package com.myapplication.ui.myactivity;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.ListView;
import android.widget.TextView;

import com.myapplication.R;
import com.squareup.picasso.Picasso;

import java.util.List;

/**
 * Created by zitaojiang on 2016/10/21.
 */
public class Collection_Adapter extends BaseAdapter {
    private  List<MyCollection> list;
    private Context context;

    public Collection_Adapter(List<MyCollection> list, Context context) {
        this.list = list;
        this.context = context;
    }

    @Override
    public int getCount() {
        return list.size();
    }

    @Override
    public Object getItem(int i) {
        return list.get(i);
    }

    @Override
    public long getItemId(int i) {
        return i;
    }
  ViewHoledr holedr=null;
    @Override
    public View getView(int i, View view, ViewGroup viewGroup) {

        if (view==null){
            view= LayoutInflater.from(context).inflate(R.layout.item_collection,null);
            holedr=new ViewHoledr();
            holedr.iv= (ImageView) view.findViewById(R.id.iv);
            holedr.tv= (TextView) view.findViewById(R.id.tv);
            view.setTag(holedr);
        }else {
            holedr= (ViewHoledr) view.getTag();
        }
        holedr.tv.setText(list.get(i).getIntro());
        Picasso.with(context).load(list.get(i).getPic()).into(holedr.iv);


        return view;
    }
   static class ViewHoledr{
       ImageView iv;
       TextView tv;
   }

}
